package com.class05;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//@WebFilter("/servletB")
//@WebFilter("/servletA") 作用：用来配置过滤器 类似xml的配置，
// 配置的是过滤的资源名servlet的url-pattern
// 销毁通常是停止项目时，tomcat自动调用销毁方法
//  执行顺序：init-->doFilter-->慕目标资源-->destroy
public class LifeCycleFilter implements Filter {

    public LifeCycleFilter(){
        System.out.println("过滤器构造器执行了");
    }
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("过滤器初始化了...........");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("放行...........");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        System.out.println("过滤器销毁了...........");
    }
}
